#!/usr/bin/env bash

set -x
set -euo pipefail
IFS=$'\n\t'

function pack() {
    PKG_NAME=${1}
    PKG_VERSION=$(grep '^Version:' ${PKG_NAME}.spec | awk '{print $2}')
    cd ..
    PROJECT_NAME="${PKG_NAME}-${PKG_VERSION}"
    git archive --format=tar --prefix=$PROJECT_NAME/ HEAD | (tar xpf -) #归档父项目后解压到指定目录
	tar zcpf ${PROJECT_NAME}.tar.gz ${PROJECT_NAME}
	/bin/mv -f ${PROJECT_NAME}.tar.gz packaging
    rm -rf ${PKG_NAME}-${PKG_VERSION}
    cd -
}

function help() {
    echo "$0 build|pack"
}


function help() {
    echo "$0 build|pack"
}

if [ "$1" == "" ]; then
    help
elif [ "$1" == "pack" ];then
    pack $2
elif [ "$1" == "test" ];then
    run_test
else
    help
fi
